package com.luomo.java.spring.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author LiuMei
 * @date 2020-12-30.
 */
@Aspect
@Component
public class MyAspect {

    @Before("execution(public int com.luomo.java.spring.aop.CalcServiceImpl.*(..))")
    public void beforeNotify() {
        System.out.println("****** @Before 前置通知");
    }

    @After("execution(public int com.luomo.java.spring.aop.CalcServiceImpl.*(..))")
    public void afterNotify() {
        System.out.println("****** @After 后置通知");
    }

    @AfterReturning("execution(public int com.luomo.java.spring.aop.CalcServiceImpl.*(..))")
    public void afterReturningNotify() {
        System.out.println("****** @AfterReturning 返回后通知");
    }

    @AfterThrowing("execution(public int com.luomo.java.spring.aop.CalcServiceImpl.*(..))")
    public void afterThrowingNotify() {
        System.out.println("****** @AfterThrowing 异常通知");
    }

    @Around("execution(public int com.luomo.java.spring.aop.CalcServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object retValue;
        System.out.println("****** @Around 环绕通知之前AAA");
        retValue = proceedingJoinPoint.proceed();
        System.out.println("****** @Around 环绕通知之后BBB");
        return retValue;
    }

}
